﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TextAdornment
{
    /// <summary>
    /// Interaction logic for CodePreviewControl.xaml
    /// </summary>
    public partial class CodePreviewControl : UserControl
    {
        private Window hostWindow;
        private TextAdornment textAdornment;
        private string generatedCode;

        public CodePreviewControl(TextAdornment textAdornment, string generatedCode)
        {
            InitializeComponent();

            // initialize host window
            hostWindow = new Window();
            hostWindow.SizeToContent = SizeToContent.WidthAndHeight;
            hostWindow.ResizeMode = ResizeMode.NoResize;
            //hostWindow.WindowStyle = WindowStyle.None;
            hostWindow.BorderThickness = new Thickness(1, 1, 1, 1);

            // set text adornment
            this.textAdornment = textAdornment;

            // set the content of code preview window
            this.generatedCode = generatedCode;
            this.tbxCodePreview.Text = generatedCode;
        }

        public void Popup(Point popupPosition)
        {
            hostWindow.Content = this;
            hostWindow.Left = popupPosition.X;
            hostWindow.Top = popupPosition.Y;
            hostWindow.ShowDialog();
        }

        public void Popup()
        {
            hostWindow.Content = this;
            hostWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            hostWindow.ShowDialog();
        }
    }
}
